package com.defang.award;

import com.defangit.award.domain.Prize;
import com.defangit.award.orm.PrizeService;
import laogen.lang.exception.ParameterNotValidException;

import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.util.List;

/**
 * Created by zhangfagen on 2019/1/12.
 */
@Path("prize")
public class PrizeResource {
    private PrizeService svr=new PrizeService();

    @GET @Produces("application/json")
    public Response all(@QueryParam("award")Integer award){
        return null;
    }

    @GET @Path("{id}") @Produces("application/json")
    public Response prize(@PathParam("id")int id){
        return Response.ok(
            new PrizeService().get(id).orElseThrow(
                    ()-> ParameterNotValidException.zeroIdOrEntityNonExist("奖项id")
            )
        ).build();
    }


    @POST @Consumes("application/json")
    public Response addPrize(@QueryParam("award")int award, List<Prize> prize){
        return Response.ok(
                svr.addPrize(award,prize)
        ).build();
    }
}
